// import { Inject, Post, Get, Body, Query } from '@midwayjs/core';
// import { CoolController, BaseController } from '@cool-midway/core';
// import { AutomationPipelineEntity } from '../../entity/pipeline'; 
// import { AutomationConditionEntity } from '../../entity/condition';
// import { AutomationTaskEntity } from '../../entity/task';
// import { AutomationPipelineService } from '../../service/app/pipeline';

// /**
//  * 管理端-自动化流水线
//  */
// @CoolController({
//   api: ['add', 'delete', 'update', 'info', 'list', 'page'],
//   entity: AutomationPipelineEntity,
//   service: AutomationPipelineService,
//   pageQueryOp: {
//     keyWordLikeFields: ['a.name'],
//     fieldEq: ['a.status', 'a.conditionRelation', 'a.triggerType'],
//     where: async (ctx) => {
//       const { createTime, effectDateType } = ctx.request.body;
//       const conditions = [];
//       if (createTime && createTime.length === 2) {
//         conditions.push([`a.createTime BETWEEN '${createTime[0]}' AND '${createTime[1]}'`]);
//       }
//       if (effectDateType !== undefined && effectDateType !== null) {
//         conditions.push([`a.effectDateType = ${effectDateType}`]);
//       }
//       return conditions;
//     },
//     select: ['a.*'],
//     join: [],
//   },
// })
// export class AdminAutomationPipelineController extends BaseController {
//   @Inject()
//   automationPipelineService: AutomationPipelineService;

//   /**
//    * 新增自动化流水线
//    */
//   @Post('/addPipeline', { summary: '新增自动化流水线' })
//   async addPipeline(@Body() params) {
//     return this.ok(await this.automationPipelineService.addPipeline(params));
//   }

//   /**
//    * 更新自动化流水线
//    */
//   @Post('/updatePipeline', { summary: '更新自动化流水线' })
//   async updatePipeline(@Body() params) {
//     return this.ok(await this.automationPipelineService.updatePipeline(params));
//   }

//   /**
//    * 删除自动化流水线
//    */
//   @Post('/deletePipeline', { summary: '删除自动化流水线' })
//   async deletePipeline(@Body('ids') ids: number[]) {
//     return this.ok(await this.automationPipelineService.deletePipeline(ids));
//   }

//   /**
//    * 获取流水线详情
//    */
//   @Get('/pipelineDetail', { summary: '获取流水线详情' })
//   async pipelineDetail(@Query('id') id: number) {
//     return this.ok(await this.automationPipelineService.pipelineDetail(id));
//   }

//   /**
//    * 启用/禁用流水线
//    */
//   @Post('/toggleStatus', { summary: '启用/禁用流水线' })
//   async toggleStatus(@Body() params: { id: number; status: number }) {
//     return this.ok(await this.automationPipelineService.togglePipelineStatus(params.id, params.status));
//   }

//   /**
//    * 手动触发流水线
//    */
//   @Post('/trigger', { summary: '手动触发流水线' })
//   async trigger(@Body('id') id: number) {
//     return this.ok(await this.automationPipelineService.triggerPipeline(id));
//   }

//   /**
//    * 获取条件类型选项
//    */
//   @Get('/conditionTypes', { summary: '获取条件类型选项' })
//   async getConditionTypes() {
//     return this.ok(await this.automationPipelineService.getConditionTypes());
//   }

//   /**
//    * 获取气象条件类型选项
//    */
//   @Get('/weatherTypes', { summary: '获取气象条件类型选项' })
//   async getWeatherTypes() {
//     return this.ok(await this.automationPipelineService.getWeatherTypes());
//   }

//   /**
//    * 获取比较方式选项
//    */
//   @Get('/compareTypes', { summary: '获取比较方式选项' })
//   async getCompareTypes() {
//     return this.ok(await this.automationPipelineService.getCompareTypes());
//   }

//   /**
//    * 获取任务操作类型选项
//    */
//   @Get('/actionTypes', { summary: '获取任务操作类型选项' })
//   async getActionTypes() {
//     return this.ok(await this.automationPipelineService.getActionTypes());
//   }

//   /**
//    * 获取流水线统计信息
//    */
//   @Get('/statistics', { summary: '获取流水线统计信息' })
//   async getStatistics() {
//     const total = await this.automationPipelineService.count();
//     const enabled = await this.automationPipelineService.count({ status: 1 });
//     const disabled = await this.automationPipelineService.count({ status: 0 });
    
//     return this.ok({
//       total,
//       enabled,
//       disabled,
//       enabledRate: total > 0 ? Math.round((enabled / total) * 100) : 0
//     });
//   }

//   /**
//    * 批量启用/禁用流水线
//    */
//   @Post('/batchToggleStatus', { summary: '批量启用/禁用流水线' })
//   async batchToggleStatus(@Body() params: { ids: number[]; status: number }) {
//     const { ids, status } = params;
//     for (const id of ids) {
//       await this.automationPipelineService.togglePipelineStatus(id, status);
//     }
//     return this.ok('批量操作成功');
//   }

//   /**
//    * 复制流水线
//    */
//   @Post('/copy', { summary: '复制流水线' })
//   async copyPipeline(@Body('id') id: number) {
//     const detail = await this.automationPipelineService.pipelineDetail(id);
//     if (!detail) {
//       return this.fail('流水线不存在');
//     }

//     const { conditions, tasks, ...pipeline } = detail;
//     delete pipeline.id;
//     delete pipeline.createTime;
//     delete pipeline.updateTime;
//     pipeline.name = `${pipeline.name}_副本`;
//     pipeline.status = 0; // 复制的流水线默认禁用

//     const newPipeline = await this.automationPipelineService.addPipeline({
//       ...pipeline,
//       conditions: conditions.map(c => {
//         delete c.id;
//         delete c.createTime;
//         delete c.updateTime;
//         delete c.pipelineId;
//         return c;
//       }),
//       tasks: tasks.map(t => {
//         delete t.id;
//         delete t.createTime;
//         delete t.updateTime;
//         delete t.pipelineId;
//         return t;
//       })
//     });

//     return this.ok(newPipeline);
//   }
// }